package gui;

import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.SWT;

/**
 * EngineSettingsComposite
 * <p/>
 *
 * @author Kunnar Klauks
 */
public class EngineSettings {
  private Group group;
  private Text txtEngineName;
  private Text txtEngineDir;
  private Text txtEngineCmd;
  private Button btnBrowseEngineDir;
  private Button btnSaveEngine;
  private Button btnRemoveEngine;
  private Button btnPlay;
  private Button btnBrowseEngineCmd;

  public void addGroupTo(Composite main) {
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = false;
    gridData.grabExcessVerticalSpace = false;
    gridData.verticalAlignment = GridData.FILL;
    group = new Group(main, SWT.NONE);
    group.setLayout(new GridLayout());
    group.setLayoutData(gridData);
    group.setText("Engine settings");
    createCmpEngineParams();
    createCmpEngineActions();
  }

  private void createCmpEngineParams() {
    Composite cmpEngineParams = new Composite(group, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.makeColumnsEqualWidth = false;
    cmpEngineParams.setLayout(gridLayout);
    GridData gridDataCmp = new GridData();
    gridDataCmp.grabExcessHorizontalSpace = true;
    gridDataCmp.verticalAlignment = GridData.FILL;
    gridDataCmp.grabExcessVerticalSpace = true;
    gridDataCmp.horizontalAlignment = GridData.FILL;
    cmpEngineParams.setLayoutData(gridDataCmp);
    Label lblEngineName = new Label(cmpEngineParams, SWT.NONE);
    lblEngineName.setText("Engine name");
    txtEngineName = new Text(cmpEngineParams, SWT.BORDER);
    GridData gridDataTxt = new GridData();
    gridDataTxt.horizontalAlignment = GridData.FILL;
    gridDataTxt.grabExcessHorizontalSpace = true;
    gridDataTxt.verticalAlignment = GridData.CENTER;
    txtEngineName.setLayoutData(gridDataTxt);
    Label lblEngineNameEmpty = new Label(cmpEngineParams, SWT.NONE);
    lblEngineNameEmpty.setText("");
    Label lblEngineDir = new Label(cmpEngineParams, SWT.NONE);
    lblEngineDir.setText("Engine directory");
    txtEngineDir = new Text(cmpEngineParams, SWT.BORDER);
    txtEngineDir.setLayoutData(gridDataTxt);
    btnBrowseEngineDir = new Button(cmpEngineParams, SWT.NONE);
    btnBrowseEngineDir.setText("...");
    Label lblEngineCmd = new Label(cmpEngineParams, SWT.NONE);
    lblEngineCmd.setText("Engine command");
    txtEngineCmd = new Text(cmpEngineParams, SWT.BORDER);
    txtEngineCmd.setLayoutData(gridDataTxt);
    btnBrowseEngineCmd = new Button(cmpEngineParams, SWT.NONE);
    btnBrowseEngineCmd.setText("...");
  }

  private void createCmpEngineActions() {
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.verticalAlignment = GridData.CENTER;
    gridData.horizontalAlignment = GridData.FILL;
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    Composite cmpEngineActions = new Composite(group, SWT.NONE);
    cmpEngineActions.setLayoutData(gridData);
    cmpEngineActions.setLayout(gridLayout);
    btnSaveEngine = new Button(cmpEngineActions, SWT.NONE);
    btnSaveEngine.setText("Save");
    btnSaveEngine.setLayoutData(gridData);
    btnRemoveEngine = new Button(cmpEngineActions, SWT.NONE);
    btnRemoveEngine.setText("Remove engine");
    btnRemoveEngine.setLayoutData(gridData);
    btnPlay = new Button(cmpEngineActions, SWT.NONE);
    btnPlay.setText("Play against engine");
    btnPlay.setLayoutData(gridData);
  }


  public Text getTxtEngineName() {
    return txtEngineName;
  }

  public Text getTxtEngineDir() {
    return txtEngineDir;
  }

  public Text getTxtEngineCmd() {
    return txtEngineCmd;
  }

  public Button getBtnBrowseEngineDir() {
    return btnBrowseEngineDir;
  }

  public Button getBtnSaveEngine() {
    return btnSaveEngine;
  }

  public Button getBtnRemoveEngine() {
    return btnRemoveEngine;
  }

  public Button getBtnPlay() {
    return btnPlay;
  }

  public Button getBtnBrowseEngineCmd() {
    return btnBrowseEngineCmd;
  }
}
